package com.shbaiche.bifenba.adapter.my;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.model.GankResults;
import com.shbaiche.bifenba.model.video.ArticleVo;
import com.shbaiche.bifenba.ui.base.WebActivity;
import com.shbaiche.bifenba.ui.video.VideoDetailActivity;

import butterknife.BindView;
import cn.droidlover.xdroid.base.SimpleRecAdapter;
import cn.droidlover.xdroid.kit.KnifeKit;
import cn.droidlover.xdroidbase.imageloader.ILFactory;

/**
 * 我的收藏-资讯列表
 */

public class CollectionListAdapter extends SimpleRecAdapter<ArticleVo, CollectionListAdapter.ViewHolder> {
    private boolean isVideo = false;
    private Context context;

    public CollectionListAdapter(Context context,boolean video) {
        super(context);
        this.isVideo = video;
        this.context = context;
    }

    @Override
    public ViewHolder newViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public int getLayoutId() {
        return R.layout.adapter_collection_infomation_list;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        final ArticleVo item = data.get(position);

        holder.tvTitle.setText(item.getTitle());
        holder.tvDate.setText(item.getDiscussNum()+"评");
        holder.tvFrom.setText(item.getSource()+" "+item.getPublishTime());
        ILFactory.getLoader().loadNet(holder.ivLogo, item.getThumbnail(), null);
        holder.ivVideo.setVisibility(isVideo?View.VISIBLE:View.GONE);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getRecItemClick() != null) {
//                    ArticleVo item = data.get(position);
//                    Bundle b = new Bundle();
//                    b.putLong("id", item.getId());
//                    VideoDetailActivity.launch((Activity) context, b);
                    WebActivity.launch((Activity) context, item.getDetailUrl(), "资讯详情",item.getId().intValue());
                }
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_logo)
        ImageView ivLogo;

        @BindView(R.id.iv_video)
        ImageView ivVideo;

        @BindView(R.id.tv_title)
        TextView tvTitle;

        @BindView(R.id.tv_date)
        TextView tvDate;

        @BindView(R.id.tv_from)
        TextView tvFrom;



        public ViewHolder(View itemView) {
            super(itemView);
            KnifeKit.bind(this, itemView);
        }
    }
}
